
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.GregorianCalendar;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Patrick
 */
public class Cromb implements Comparable{

    private String author;
    private String message;
    private GregorianCalendar datetime;
    private double longitude;
    private double latitude;
    private double distance;
    private double orientation;
    private int userId;
    private int likeCounter;
    private int id;

    public Cromb(String author, String message, GregorianCalendar datetime, double lon, double lat) {
        this.author = author;
        this.message = message;
        this.datetime = datetime;
        this.longitude = lon;
        this.latitude = lat;
        this.distance = 0;
    }

    public Cromb(ResultSet rs, double lon, double lat) throws SQLException {
        this.id = rs.getInt("id");
        this.author = rs.getString("author");
        this.message = rs.getString("message");
        this.datetime = new GregorianCalendar();
        datetime.setTimeInMillis(rs.getTimestamp("datetime").getTime());
        this.longitude = rs.getDouble("longitude");
        this.latitude = rs.getDouble("latitude");
        this.distance = GeoTools.distance(this.latitude, lat, this.longitude, lon, 0, 0);
        this.orientation = GeoTools.bearing(lat, lon, this.latitude, this.longitude);

        if (rs.getObject("userid") != null) {
            this.userId = rs.getInt("userid");
        } else {
            this.userId = -1;
        }
        if (rs.getObject("likecounter") != null) {
        this.likeCounter = rs.getInt("likecounter");
        } else {
            this.likeCounter=0;
        }
    }

    /**
     * @return the author
     */
    public String getAuthor() {
        return author;
    }

    /**
     * @param author the author to set
     */
    public void setAuthor(String author) {
        this.author = author;
    }

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * @return the entryTime
     */
    public GregorianCalendar getEntryTime() {
        return datetime;
    }

    /**
     * @return the distance
     */
    public double getDistance() {
        return distance;
    }

    /**
     * @return the orientation
     */
    public double getOrientation() {
        return orientation;
    }

    /**
     * @param orientation the orientation to set
     */
    public void setOrientation(double orientation) {
        this.orientation = orientation;
    }

    /**
     * @return the userId
     */
    public int getUserId() {
        return userId;
    }

    /**
     * @return the likeCounter
     */
    public int getLikeCounter() {
        return likeCounter;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @return the longitude
     */
    public double getLongitude() {
        return longitude;
    }

    /**
     * @return the latitude
     */
    public double getLatitude() {
        return latitude;
    }

    public int compareTo(Object o) {
        if (o instanceof Cromb){
            Cromb c = (Cromb)o;
            return (int)((this.distance - c.distance)*1000);
        }
        return 0;
    }
}
